{% extends  data.theme + "/_base.html" %}

{% import "bootstrap/wtf.html" as wtf %}

{% block title %} {{data.title}} {% endblock %}

{%- block head -%} 
{{ super() }}
{%- endblock -%}

{% set form = data.form %}

{%- block body -%}

<div class="col-md-12" >
{% for message in get_flashed_messages() %}
<div class="alert alert-warning">
<button type="button" class="close" data-dismiss="alert">&times;</button>
{{ message }}
</div>
{% endfor %}

<a href="{{url_for('clips.item_list')}}" class="btn btn-default">← Back</a>
<p>
{# basic horizontal form_type="inline" #}
{{ wtf.quick_form(form) }}
</div>

{% endblock %}

<div>Bootstrap lines</div>
<form method="post" name="line_wtf">
    {% for msg in get_flashed_messages() %}
	{{ msg }}
    {% endfor %}
    {{ form.csrf_token }}
    {{ wtf.form_field(form.title) }}
    {{ wtf.form_field(form.content) }}
    {{ wtf.form_field(form.readme) }}
    {{ wtf.form_field(form.category_id) }}
    {{ wtf.form_errors(form, hiddens="only") }}
    {{ wtf.form_field(form.submit) }}
</form>


不在block里的都是不输出的 放着做参考用

<div>Most Simple : 服务端验证</div>
 <form method="post" name="line_form">
    {% for msg in get_flashed_messages() %}
	{{ msg }}
    {% endfor %}
    {{ form.csrf_token }}
    {{ form.title.label }}
    {{ form.title() }}
    {{ form.content.label }}
    {{ form.content() }}
    {{ form.submit() }}
</form>

{% if form.errors %}
  明文输出JsonError:  {{ form.errors }}
{% endif %}

<div>手动Bootstrap 服务端验证后render到界面</div>
<form method="post" id ="itemform" class="form-horizontal" role="form">

    {{ form.hidden_tag() }}
    <span class="fade" style="color:#f00;">
    {% for message in get_flashed_messages() %}{{ message }}{% endfor %}
    </span>

    <div class="form-group">
	    <label for="title" class="col-sm-2 control-label">标题</label>
	    <div class=col-sm-10">
    {{ form.title(placeholder="标题",class="form-control",style="width:40%;") }}
    {% for error in form.title.errors %} {{ error }} {% endfor %}
	    </div>
    </div>

    <div class="form-group">
	    <label for="title" class="col-sm-2 control-label">内容</label>
	    <div class=col-sm-10">
    {{ form.content(placeholder="内容",class="form-control",style="width:40%;") }}
    {% for error in form.content.errors %} {{ error }} {% endfor %}
	    </div>
    </div>
    <div class="form-group">
	    <label for="title" class="col-sm-2 control-label"></label>
	    <div class=col-sm-10">
		<button id="btn_save" class="super normal button">保存</button>
	    </div>
    </div>
</form>

-------------------------------------

{% block script %}
{{ super() }}
<script type="text/javascript">
$(function() {
    $('#btn_save').on("click",function(){
        $("#btn_save").attr('disabled',true);
        var form= $("#itemform")[0];
	if(form){
	    //form.pwd2.value = md5(form.pwd2.value);
	    form.action="{{ url_for('clips.item_edit') }}";
	    form.submit();
	}
        $("#btn_save").attr('disabled',false);
    });
});
</script>
{% endblock %}
